package com.sky.task;

import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class OrderTask {

    @Autowired
    private OrderMapper orderMapper;

//15分钟未支付的订单改为已取消
    @Scheduled(cron = "0 * * * * ?")//每分钟执行一次
    public void processTimeoutOrder(){
        LocalDateTime time = LocalDateTime.now().plusMinutes(-15);
        orderMapper.updateTimeout(1,LocalDateTime.now(),time);
    }

//当天忘记点送达的订单，1点打烊后自动设置送达
    @Scheduled(cron = "0 0 1 * * ?")
    public void processSeliveryOrder(){
        LocalDateTime time = LocalDateTime.now().plusHours(-13);
        orderMapper.updateSelivery(4,time);
    }

}
